<?php
namespace app\admin\model;

class Category extends Base{


    //public function getStatusTxtAttr($value,$data){
    //    $status = [
    //        0 => '禁用',
    //        1 => '可用',
    //    ];
    //    return $status[$data['status']];
   // }

    public function getTree(){
        $data = $this->select();
        return $this->_reSort($data);
    }
    private function _reSort($data, $pid=0, $level=0, $isClear=TRUE){
        static $ret = array();
        if($isClear)
            $ret = array();
        foreach ($data as $k => $v) {
            if($v['pid'] == $pid) {
                $v['level'] = $level;
                $ret[] = $v;
                $this->_reSort($data, $v['id'], $level+1, FALSE);
            }
        }
        return $ret;
    }

}
